//
//  LocationOperation.m
//  HB
//
//  Created by 陶秋安 on 16/3/8.
//  Copyright © 2016年 孙智慧. All rights reserved.
//

#import "LocationOperation.h"

@implementation LocationOperation

- (id) initWithId:(id) target
{
    if (self = [super init])
    {
        if (IS_IOS8)
        {
            [UIApplication sharedApplication].idleTimerDisabled = TRUE;
            
            locationmanager = [[CLLocationManager alloc] init];
            
            [locationmanager requestAlwaysAuthorization];        //NSLocationAlwaysUsageDescription
            
            [locationmanager requestWhenInUseAuthorization];     //NSLocationWhenInUseDescription
            
            locationmanager.delegate = target;
        }
    }
    return self;
}

#pragma mark 地理位置
-(void)getLat
{
    //__block __weak ViewController *wself = self;
    
    if (IS_IOS8) {
        
        [[CCLocationManager shareLocation] getLocationCoordinate:^(CLLocationCoordinate2D locationCorrrdinate) {
            
            NSLog(@"%f %f",locationCorrrdinate.latitude,locationCorrrdinate.longitude);


        }];
    }
    
}

-(void)getCity
{
    //__block __weak BaseController *wself = self;
    if (IS_IOS8)
    {
        [[CCLocationManager shareLocation]getCity:^(NSString *cityString) {
            NSLog(@"城市：%@",cityString);
        }];
    }
}


-(void)getAllInfo
{
    // __block NSString *string;
    // __block __weak ViewController *wself = self;

    if (IS_IOS8) {
        
        [[CCLocationManager shareLocation]getLocationCoordinate:^(CLLocationCoordinate2D locationCorrrdinate) {
            //string = [NSString stringWithFormat:@"%f %f",locationCorrrdinate.latitude,locationCorrrdinate.longitude];
        } withAddress:^(NSString *addressString) {
            NSLog(@"%@",addressString);
            //string = [NSString stringWithFormat:@"%@\n%@",string,addressString];
            //[wself setLabelText:string];
            
        }];
    }
    
}

@end
